package edu.umd.ion.wavemeter.service;


/**
 * Exception class for failure of Get-Functions
 * @author monroe-lab
 *
 */
public class WavemeterGetException extends WavemeterException {
	static final long serialVersionUID = 1;
	public static final String[] Message = { "no value", "no signal", "bad signal",
		"underexposed", "overexposed", "no wavemeter",
		"unavailable", "nothing changed", "no pulse",
		"err 9", "err 10", "err 11", "err 12" , 
		"Inf", "out of range", "unit unavailable" };
	
	public WavemeterGetException() {
		super();
	}
	
	public WavemeterGetException(String message) {
		super(message);
	}
	
	/**
	 * Generate Exception with error mesage built from the name of the
	 * calling funtion and the errorcode returned by the WavemeterLibrary
	 * Get-Function.
	 * @param function
	 * @param errorcode
	 */
	public WavemeterGetException(String function, int errorcode) {
		super(formatMessage(function,errorcode));
	}
	
	protected static String formatMessage(String function, int errorcode)
	{
		if ( errorcode>0 || errorcode<-15 )
			return "Wavemeter function '"+function+"' errorcode out of range";
		else
			return "Wavemeter function '"+function+"' reported error '"+Message[-errorcode]+"'";		
	}
}
